#include<bits/stdc++.h>
using namespace std;

int n,m;
int k,p,x;
bool exist[100001];
typedef struct Node{
	int num;
	struct Node* prev;
	struct Node* next;
	Node(int num_){
		num=num_;
		prev=nullptr;
		next=nullptr;
	}
	Node(int num_,struct Node* prev_,struct Node* next_){
		num=num_;
		prev=prev_;
		next=next_;
	}
} Node;
map<int,Node*> mymap;

int main(){
	cin>>n;
	Node* head=new Node{-1};
	head->next=new Node{1,head,nullptr};
	mymap[1]=head->next;
	for(int i=2;i<=n;i++){
		cin>>k>>p;
		auto pos=mymap[k];
		auto node=new Node{i};
		if(p==0){
			pos->prev->next=node;
			node->prev=pos->prev;
			pos->prev=node;
			node->next=pos;
		}
		else if(p==1){
			if(pos->next!=nullptr){
				pos->next->prev=node;
				node->next=pos->next;
				node->prev=pos;
				pos->next=node;
			}
			else{
				node->prev=pos;
				node->next=nullptr;
				pos->next=node;
			}
		}
		mymap[i]=node;
	}
	cin>>m;
	memset(exist,true,sizeof(exist));
	for(int i=0;i<m;i++){
		cin>>x;
		if(exist[x]){
			auto pos=mymap[x];
			if(pos->next!=nullptr){
				pos->prev->next=pos->next;
				pos->next->prev=pos->prev;
			}
			else{
				pos->prev->next=nullptr;
			} 
			pos->prev=nullptr;
			pos->next=nullptr;
			exist[x]=false;
		}
	}
	//print
	for(auto p=head->next;p!=nullptr;p=p->next){
		cout<<p->num<<' ';
	}
	return 0;
}
